<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Git学习-本地版本控制与版本回溯 | ShenShilei's Blog</title><meta name="keywords" content="Git"><meta name="author" content="Shen Shilei"><meta name="copyright" content="Shen Shilei"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><meta name="description" content="使用Git对代码进行版本控制。">
<meta property="og:type" content="article">
<meta property="og:title" content="Git学习-本地版本控制与版本回溯">
<meta property="og:url" content="https://blog.shenshilei.site/post/b00a/index.html">
<meta property="og:site_name" content="ShenShilei&#39;s Blog">
<meta property="og:description" content="使用Git对代码进行版本控制。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/TrakaiLithuania_ZH-CN0447602818_1920x1080.jpg">
<meta property="article:published_time" content="2020-02-23T16:00:00.000Z">
<meta property="article:modified_time" content="2020-07-05T12:17:55.000Z">
<meta property="article:author" content="Shen Shilei">
<meta property="article:tag" content="Git">
<meta property="article:tag" content="版本控制">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/TrakaiLithuania_ZH-CN0447602818_1920x1080.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://blog.shenshilei.site/post/b00a/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css"><script>var GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: {"limitDay":180,"position":"top","messagePrev":"这是一篇创建于","messageNext":"天前的文章，其中的信息可能已经有所发展或是发生改变。"},
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: Shen Shilei","link":"链接: ","source":"来源: ShenShilei's Blog","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  ClickShowText: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"top-center"},
  justifiedGallery: {
    js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
    css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
};

var saveToLocal = {
  set: function setWithExpiry(key, value, ttl) {
    const now = new Date()
    const expiryDay = ttl * 86400000
    const item = {
      value: value,
      expiry: now.getTime() + expiryDay,
    }
    localStorage.setItem(key, JSON.stringify(item))
  },

  get: function getWithExpiry(key) {
    const itemStr = localStorage.getItem(key)

    if (!itemStr) {
      return undefined
    }
    const item = JSON.parse(itemStr)
    const now = new Date()

    if (now.getTime() > item.expiry) {
      localStorage.removeItem(key)
      return undefined
    }
    return item.value
  }
}</script><script id="config_change">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2020-07-05 20:17:55'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(function () {  window.activateDarkMode = function () {
    document.documentElement.setAttribute('data-theme', 'dark')
    if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
    }
  }
  window.activateLightMode = function () {
    document.documentElement.setAttribute('data-theme', 'light')
   if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
    }
  }
  const autoChangeMode = '1'
  const t = saveToLocal.get('theme')
  if (autoChangeMode === '1') {
    const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
    const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
    const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
    const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified
    if (t === undefined) {
      if (isLightMode) activateLightMode()
      else if (isDarkMode) activateDarkMode()
      else if (isNotSpecified || hasNoSupport) {
        const now = new Date()
        const hour = now.getHours()
        const isNight = hour <= 6 || hour >= 18
        isNight ? activateDarkMode() : activateLightMode()
      }
      window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
        if (saveToLocal.get('theme') === undefined) {
          e.matches ? activateDarkMode() : activateLightMode()
        }
      })
    } else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else if (autoChangeMode === '2') {
    const now = new Date()
    const hour = now.getHours()
    const isNight = hour <= 6 || hour >= 18
    if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
    else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else {
    if (t === 'dark') activateDarkMode()
    else if (t === 'light') activateLightMode()
  }})()</script><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Noto+Serif+SC"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/kang-static/Hexo/css/iconfont.min.css"><style type="text/css">.aplayer.aplayer-narrow .aplayer-body{left: -66px !important;transition: left 1s;} .aplayer.aplayer-narrow .aplayer-body:hover{left: 0 !important;}</style><style type="text/css">body{cursor: url(https://cdn.jsdelivr.net/gh/Justlovesmile/CDN/image/cursor.ico),default}</style><meta name="generator" content="Hexo 5.4.0"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="https://cdn.jsdelivr.net/gh/shenshilei1022/cdn@1.6/img/custom/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">92</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">60</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">38</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/artitalk/"><i class="fa-fw fa fa-comment"></i><span> 说说</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 文章</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></li><li><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page" href="/analytics/"><i class="fa-fw fas fa-chart-line"></i><span> 统计</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 清单</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/bangumis/"><i class="fa-fw fab fa-youtube"></i><span> 番剧</span></a></li><li><a class="site-page" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li><li><a class="site-page" href="/books/"><i class="fa-fw fas fa-book"></i><span> 书单</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 工具箱</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/box/"><i class="fa-fw fas fa-th-large"></i><span> 网站聚合</span></a></li><li><a class="site-page" target="_blank" rel="noopener" href="https://cdn.jsdelivr.net/gh/shenshilei1022/cdn@2.0/"><i class="fa-fw fa fa-hdd"></i><span> MyCDN</span></a></li><li><a class="site-page" href="/note/"><i class="fa-fw fas fa-business-time"></i><span> 便利贴</span></a></li><li><a class="site-page" target="_blank" rel="noopener" href="https://music.shenshilei.site/"><i class="fa-fw fas fa-music"></i><span> 音乐播放器</span></a></li><li><a class="site-page" target="_blank" rel="noopener" href="https://webssh.shenshilei.site/"><i class="fa-fw fas fa-terminal"></i><span> SSH在线连接</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/comment/"><i class="fa-fw fa fa-pencil-alt"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-paperclip"></i><span> 关于</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/about/"><i class="fa-fw fas fa-rocket"></i><span> 我</span></a></li><li><a class="site-page" target="_blank" rel="noopener" href="https://shenshilei1022.avosapps.us/"><i class="fa-fw fas fa-list-alt"></i><span> 评论管理</span></a></li><li><a class="site-page" target="_blank" rel="noopener" href="http://bt.shenshilei.site:8888/shenshilei"><i class="fa-fw fas fa-window-maximize"></i><span> 服务器管理</span></a></li><li><a class="site-page" target="_blank" rel="noopener" href="https://console.leancloud.app/applist.html#/apps"><i class="fa-fw fas fa-window-restore"></i><span> leancloud应用</span></a></li></ul></div></div></div></div><div id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url(https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/TrakaiLithuania_ZH-CN0447602818_1920x1080.jpg)"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">ShenShilei's Blog</a></span><span id="menus"><div id="search_button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/artitalk/"><i class="fa-fw fa fa-comment"></i><span> 说说</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 文章</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></li><li><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li><li><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page" href="/analytics/"><i class="fa-fw fas fa-chart-line"></i><span> 统计</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 清单</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/bangumis/"><i class="fa-fw fab fa-youtube"></i><span> 番剧</span></a></li><li><a class="site-page" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li><li><a class="site-page" href="/books/"><i class="fa-fw fas fa-book"></i><span> 书单</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 工具箱</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/box/"><i class="fa-fw fas fa-th-large"></i><span> 网站聚合</span></a></li><li><a class="site-page" target="_blank" rel="noopener" href="https://cdn.jsdelivr.net/gh/shenshilei1022/cdn@2.0/"><i class="fa-fw fa fa-hdd"></i><span> MyCDN</span></a></li><li><a class="site-page" href="/note/"><i class="fa-fw fas fa-business-time"></i><span> 便利贴</span></a></li><li><a class="site-page" target="_blank" rel="noopener" href="https://music.shenshilei.site/"><i class="fa-fw fas fa-music"></i><span> 音乐播放器</span></a></li><li><a class="site-page" target="_blank" rel="noopener" href="https://webssh.shenshilei.site/"><i class="fa-fw fas fa-terminal"></i><span> SSH在线连接</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/comment/"><i class="fa-fw fa fa-pencil-alt"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-paperclip"></i><span> 关于</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/about/"><i class="fa-fw fas fa-rocket"></i><span> 我</span></a></li><li><a class="site-page" target="_blank" rel="noopener" href="https://shenshilei1022.avosapps.us/"><i class="fa-fw fas fa-list-alt"></i><span> 评论管理</span></a></li><li><a class="site-page" target="_blank" rel="noopener" href="http://bt.shenshilei.site:8888/shenshilei"><i class="fa-fw fas fa-window-maximize"></i><span> 服务器管理</span></a></li><li><a class="site-page" target="_blank" rel="noopener" href="https://console.leancloud.app/applist.html#/apps"><i class="fa-fw fas fa-window-restore"></i><span> leancloud应用</span></a></li></ul></div></div><span class="close" id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></span></span></nav><div id="post-info"><h1 class="post-title">Git学习-本地版本控制与版本回溯</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-02-23T16:00:00.000Z" title="发表于 2020-02-24 00:00:00">2020-02-24</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2020-07-05T12:17:55.000Z" title="更新于 2020-07-05 20:17:55">2020-07-05</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%B7%A5%E5%85%B7%E4%BD%BF%E7%94%A8/">工具使用</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%B7%A5%E5%85%B7%E4%BD%BF%E7%94%A8/Git/">Git</a></span></div><div class="meta-secondline"> <span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.2k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>7分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span><span class="post-meta-separator">|</span><span class="post-meta-commentcount"><i class="far fa-comments fa-fw post-meta-icon"></i><span class="post-meta-label">评论数:</span><a href="/post/b00a/#post-comment" itemprop="discussionUrl"><span class="valine-comment-count comment-count" data-xid="/post/b00a/" itemprop="commentCount"></span></a></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><p>以前也了解学习过Git这一版本控制系统，但没有经常使用的情况下，很多命令就忘得一干二净了。正好最近有空闲时间，决定将它重新拾起来，毕竟Git和GitHub作为十分优秀的版本控制和代码托管平台，很有必要把它学好~</p>
<h2 id="1-Git简介"><a href="#1-Git简介" class="headerlink" title="1. Git简介"></a>1. Git简介</h2><h3 id="1-1-集中式版本控制和分布式版本控制"><a href="#1-1-集中式版本控制和分布式版本控制" class="headerlink" title="1.1 集中式版本控制和分布式版本控制"></a>1.1 集中式版本控制和分布式版本控制</h3><p>Git是Linux创建者Linus使用C语言写的一个分布式版本控制系统。另一非常出名的版本控制系统是SVN，它是集中式的版本控制系统。它们之间有什么区别呢？</p>
<p>集中式版本控制系统，版本库是集中放在中央服务器的。需要使用的时候，需要先从中央处理器获取最新的版本库，开始进行自己的工作，工作完后再将版本库推送回中央服务器。而这样的最大缺点就是必须要联网，在有些情况下还是有些不方便的。</p>
<p><img src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/%E9%9B%86%E4%B8%AD%E5%BC%8F.png" alt=""></p>
<p>而在分布式版本控制系统中，没有所谓的中央服务器，每台PC上都有完整的版本库，工作的时候直接在本地就可以操作。如果两个人之间需要协作，那他们互相推送自己的修改就可以了。但考虑到多人协作的情况，Git也有一个“中央服务器”——GitHub，方便多人交换各自的修改。</p>
<p><img src="https://gitee.com/shenshilei1022/hugo_image_resource/master/imgs/%E5%88%86%E5%B8%83%E5%BC%8F.png" alt=""></p>
<h3 id="1-2-为什么要使用Git？"><a href="#1-2-为什么要使用Git？" class="headerlink" title="1.2 为什么要使用Git？"></a>1.2 为什么要使用Git？</h3><p>比如当你写毕业论文的时候，最开始的时候是初稿，然后经过修改你的文件夹会变成这样…</p>
<p><img src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/%E4%B8%BA%E4%BB%80%E4%B9%88%E8%A6%81%E4%BD%BF%E7%94%A8Git.png" alt=""></p>
<p>这样修改多次之后，就算是记性再好的人也难免记不清每个文档相较于最初做了哪些修改，十分容易混淆。而且如果你想回到之前你修改过的某一个版本，这么多的文档下，也很难记得符合自己要求的是哪一个了吧😂。如果能有下面这样的版本记录，那么对于这些修改就得心应手了。</p>
<div class="table-container">
<table>
<thead>
<tr>
<th>版本</th>
<th>文件名</th>
<th>用户</th>
<th>说明</th>
<th>日期</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>readme.txt</td>
<td>小明</td>
<td>增加readme文档</td>
<td>2020.1.19</td>
</tr>
<tr>
<td>2</td>
<td>readme.txt</td>
<td>小华</td>
<td>删除配置说明</td>
<td>2020.2.5</td>
</tr>
<tr>
<td>…</td>
<td>…</td>
<td>…</td>
<td>…</td>
<td>…</td>
</tr>
</tbody>
</table>
</div>
<p>这样就进入了版本控制的20世纪~</p>
<h3 id="1-3-安装Git"><a href="#1-3-安装Git" class="headerlink" title="1.3 安装Git"></a>1.3 安装Git</h3><p>进入<a target="_blank" rel="noopener" href="https://git-scm.com/">Git</a>官网下载Windows版本的二进制文件进行傻瓜式安装即可。</p>
<p>安装好后，打开git bash，配置用户名和邮箱（因为Git是分布式版本控制系统，因此每台机器都需要表明自己的身份。）</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git config --global user.name &quot;你的用户名&quot;</span><br><span class="line">git config --global user.email &quot;你的邮箱名&quot;</span><br></pre></td></tr></table></figure>
<p>global参数表示这台机器上的所有仓库都会使用这个配置。</p>
<h2 id="2-使用Git在本地进行版本控制"><a href="#2-使用Git在本地进行版本控制" class="headerlink" title="2. 使用Git在本地进行版本控制"></a>2. 使用Git在本地进行版本控制</h2><h3 id="2-1-初始化版本库"><a href="#2-1-初始化版本库" class="headerlink" title="2.1 初始化版本库"></a>2.1 初始化版本库</h3><p>打开git bash，创建新文件夹LearnIt，切换到文件夹中</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mkdir LearnIt</span><br><span class="line">cd LearnIt</span><br></pre></td></tr></table></figure>
<p>使用git init初始化版本库<code>git init</code></p>
<p>这就在本地创建好了一个新的版本库(<strong>实际上版本库就是文件夹下面的.git文件夹下的内容</strong>[看不见该文件夹的可以打开查看隐藏文件选项])。</p>
<h3 id="2-2-add和commit"><a href="#2-2-add和commit" class="headerlink" title="2.2 add和commit"></a>2.2 add和commit</h3><p>创建好版本库之后，怎样进行文件的版本控制呢？</p>
<p>需要先了解一下Git的工作原理</p>
<p><img src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/Git%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86.png" alt=""></p>
<p>这里的工作区(Working Directory)就是LearnIt文件夹下的内容，版本库就是.git文件夹下的内容。版本库分为两个部分：暂存区(stage)和主分支(master)。</p>
<p>整个版本控制的流程大致就是将工作区的修改先提交到暂存区，再将暂存区的内容推送到主分支上，这样版本库就保存了工作区最新的信息。当工作区的内容更新时，需要进行相同的操作来更新版本库。最终操作版本库就可以对不同版本的工作区内容实现版本控制了。</p>
<p>那么在LearnIt文件夹下创建readme.txt</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim readme.txt</span><br></pre></td></tr></table></figure>
<p><img src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/%E6%96%B0%E5%BB%BA%E5%B7%A5%E4%BD%9C%E5%8C%BA%E6%96%87%E4%BB%B6.png" alt=""></p>
<p>输完后按<kbd>Esc</kbd>进入末行模式，输入wq保存退出。</p>
<p>使用<code>git add readme.txt</code>命令将工作区文件添加到暂存区。</p>
<p>使用<code>git commit -m &quot;添加readme.txt&quot;</code>命令将暂存区文件添加到master主分支（””内部是这次提交的注释，帮助你了解每个版本究竟干了什么事情。）。</p>
<p>使用<code>git status</code>查看Git当前状态。</p>
<p><img src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/%E7%AC%AC%E4%B8%80%E6%AC%A1%E6%8F%90%E4%BA%A4%E6%88%90%E5%8A%9F.png" alt=""></p>
<p>提示工作区是干净的，即工作区的所有修改已经全部提交到了版本库。</p>
<h3 id="2-3-修改文件进行版本更新"><a href="#2-3-修改文件进行版本更新" class="headerlink" title="2.3 修改文件进行版本更新"></a>2.3 修改文件进行版本更新</h3><figure class="highlight vim"><figcaption><span>readme.txt```进入文本进行修改</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">![](http<span class="variable">s:</span>//gitee.<span class="keyword">com</span>/shenshilei1022/hugo_image_resource/raw/master/imgs/%E4%BF%AE%E6%<span class="number">94</span>%B9readme%E6%<span class="number">96</span>%<span class="number">87</span>%E4%BB%B6.png)</span><br><span class="line"></span><br><span class="line">这时使用```git status```查看Git状态</span><br><span class="line"></span><br><span class="line">![](http<span class="variable">s:</span>//gitee.<span class="keyword">com</span>/shenshilei1022/hugo_image_resource/raw/master/imgs/Git%E7%<span class="number">8</span>A%B6%E6%<span class="number">80</span>%<span class="number">81</span>_2.png)</span><br><span class="line"></span><br><span class="line">提示有修改没有提交到暂存区，且没有commit</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>git add readme.txt<br>git commit -m “append GPL”<br>```</p>
<p>使用上述命令进行版本库更新。</p>
<p>使用<code>git log</code>命令就可以查看版本一览了，如果嫌显示信息过于繁杂，则可以带上<code>--oneline</code>参数，显示格式即如博文前面的表格格式了。</p>
<p><img src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/log%E6%98%BE%E7%A4%BA%E7%89%88%E6%9C%AC%E4%B8%80%E8%A7%88.png" alt=""></p>
<p>黄色的一串字母数字码是commit id(版本号)，之后版本回溯的时候会用到。</p>
<p>HEAD -&gt; master 表示当前所处的位置在master分支，且指向”append GPL”版本，(HEAD是一个指针，移动它就相当于移动当前所在的版本。之后要用)。</p>
<h3 id="2-4-版本回溯"><a href="#2-4-版本回溯" class="headerlink" title="2.4 版本回溯"></a>2.4 版本回溯</h3><p>再修改一下readme.txt</p>
<p>此时先不要add进暂存区，使用<code>git diff</code>命令可以比较目前工作区文件和版本库当前版本文件的区别。</p>
<p><img src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/%E6%AF%94%E8%BE%83%E5%B7%A5%E4%BD%9C%E5%8C%BA%E5%92%8C%E7%89%88%E6%9C%AC%E5%BA%93%E6%96%87%E4%BB%B6%E7%9A%84%E4%B8%8D%E5%90%8C.png" alt=""></p>
<p>add commit更新版本库，查看版本一览</p>
<p><img src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/%E7%89%88%E6%9C%AC%E4%B8%80%E8%A7%88_%E4%B8%89%E6%9D%A1%E7%89%88%E6%9C%AC%E4%BF%A1%E6%81%AF.png" alt=""></p>
<p>此时，若觉得当前这个professional版本是多余的，想回到append GPL版本，使用<code>git reset --hard HEAD^</code>来回到上个版本(HEAD^表示当前HEAD的前一个版本，HEAD^^则表示前两个，以此类推。当然，数量多了以后可以使用HEAD~20表示HEAD的前20个版本)。</p>
<p><img src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/%E7%89%88%E6%9C%AC%E5%9B%9E%E6%BA%AF.png" alt=""></p>
<p>从而回到了append GPL版本，打开文件，确实回到了之前的版本。</p>
<p><img src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/%E4%BF%AE%E6%94%B9readme%E6%96%87%E4%BB%B6.png" alt=""></p>
<p>如果一个版本库中有几十上百个版本，使用HEAD^这种方法很繁杂，这时候轮到commit id出场了，<code>git reset --hard 版本号</code>来切换到版本号对应的版本。<strong>小技巧：版本号不用输全，一般输个四五位就够了~</strong></p>
<p>但是又有情况出现了，又想回到append professional版本了，可是<code>git log</code>命令已经不能显示append professional版本的版本号了，怎么办呢？使用<code>git reflog</code>命令查看历史操作，可以看到需要的版本号，再使用reset命令即可达到回到未来的操作啦！</p>
<p><img src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/reflog%E6%9F%A5%E7%9C%8B%E5%8E%86%E5%8F%B2%E5%91%BD%E4%BB%A4.png" alt=""></p>
<h3 id="2-5-撤销操作"><a href="#2-5-撤销操作" class="headerlink" title="2.5 撤销操作"></a>2.5 撤销操作</h3><p>编辑文件readme.txt.</p>
<p><img src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/%E6%96%87%E4%BB%B6%E4%B8%AD%E5%8A%A0%E4%BA%86%E4%B8%8D%E8%83%BD%E6%8F%90%E4%BA%A4%E7%9A%84%E8%AF%9D.png" alt=""></p>
<p>当保存之后，你突然发现不对，最后一句不能出现在文件当中。此时，再打开文件把这句话删掉吗😂？当然这样也可以，但Git还提供了更简单的方法。使用<code>git checkout -- 文件名</code>可以直接撤销工作区的改动。</p>
<p>但如果已经把修改提交到了暂存区，需要使用<code>git reset HEAD readme.txt</code>把暂存区的文件撤销回工作区(使用HEAD表示最新的版本)，在使用<code>git checkout -- 文件名</code>撤销工作区的改动。</p>
<h3 id="2-6-删除操作"><a href="#2-6-删除操作" class="headerlink" title="2.6 删除操作"></a>2.6 删除操作</h3><p>添加一个test.txt文件提交到版本库。通常我们删除文件是从文件管理器中直接删除或是使用rm命令。此时查看Git状态</p>
<p><img src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/%E5%88%A0%E9%99%A4%E6%96%87%E4%BB%B6Git%E7%8A%B6%E6%80%81.png" alt=""></p>
<p>此时，如果你仍旧需要删除文件，则执行<code>git rm 文件名</code>，再进行提交<code>git commit -m &quot;删除test.txt&quot;</code>，现在，文件就从版本库中被删除了。</p>
<p>另一种情况就是删错文件了，不过不要紧，版本库中还有这个文件，又因为暂存区没有变动。直接执行<code>git checkout -- test.txt</code>来撤销工作区的操作。但是如果已经执行了<code>git rm 文件名</code>，这时暂存区发生了变动，需要先撤销暂存区变动（<code>git reset HEAD 文件名</code>），再撤销工作区变动（<code>git checkout -- 文件名</code>）.</p>
<p><strong>删除的文件之前必须提交到过版本库才可恢复！</strong></p>
<h2 id="3-总结"><a href="#3-总结" class="headerlink" title="3. 总结"></a>3. 总结</h2><p>Git在本地进行版本控制分为以下步骤：</p>
<p>新建版本库<br>add commit实现版本添加<br>reset实现版本回溯<br>checkout reset撤销工作区、暂存区操作<br>rm 删除操作</p>
<p>log reflog查看版本一览、历史版本信息<br>status查看Git状态</p>
<h2 id="4-参考"><a href="#4-参考" class="headerlink" title="4. 参考"></a>4. 参考</h2><ul>
<li><a target="_blank" rel="noopener" href="https://www.liaoxuefeng.com/wiki/896043488029600">廖雪峰Git教程</a></li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">Shen Shilei</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://blog.shenshilei.site/post/b00a/">https://blog.shenshilei.site/post/b00a/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://blog.shenshilei.site" target="_blank">ShenShilei's Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Git/">Git</a><a class="post-meta__tags" href="/tags/%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/">版本控制</a></div><div class="post_share"><div class="social-share" data-image="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/TrakaiLithuania_ZH-CN0447602818_1920x1080.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏<div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/WeChanSQ.png" target="_blank"><img class="post-qr-code-img" src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/WeChanSQ.png" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/AliPayQR.png" target="_blank"><img class="post-qr-code-img" src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/AliPayQR.png" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/post/2476/"><img class="prev-cover" src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/AerialKluaneNP_ZH-CN4080112842_1920x1080.jpg" onerror="onerror=null;src='/img/404.jpg'"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Git学习-远程仓库</div></div></a></div><div class="next-post pull-right"><a href="/post/46ac/"><img class="next-cover" src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/Lanternfestival2020_ZH-CN9333703076_1920x1080.jpg" onerror="onerror=null;src='/img/404.jpg'"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">局域网下Windows和iPad之间互传文件</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/post/2353/" title="Git学习-分支"><img class="cover" src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/ElPit_ZH-CN1174143508_1920x1080.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-02-27</div><div class="title">Git学习-分支</div></div></a></div><div><a href="/post/2476/" title="Git学习-远程仓库"><img class="cover" src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/AerialKluaneNP_ZH-CN4080112842_1920x1080.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-02-25</div><div class="title">Git学习-远程仓库</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside_content" id="aside_content"><div class="card-widget card-info"><div class="card-content"><div class="card-info-avatar is-center"><img class="avatar-img" src="https://cdn.jsdelivr.net/gh/shenshilei1022/cdn@1.6/img/custom/avatar.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">Shen Shilei</div><div class="author-info__description"></div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">92</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">60</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">38</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/shenshilei1022"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/shenshilei1022" target="_blank" title="Github"><i class="iconfont icon-github1"></i></a><a class="social-icon" href="mailto:1774822536@qq.com" target="_blank" title="Email"><i class="iconfont icon-youxiang"></i></a><a class="social-icon" href="https://gitee.com/shenshilei1022" target="_blank" title="Gitee"><i class="iconfont icon-github2"></i></a><a class="social-icon" href="https://music.163.com/#/user/home?id=77600006" target="_blank" title="Netease Music"><i class="iconfont icon-wangyiyunyinle"></i></a><a class="social-icon" href="https://space.bilibili.com/15250718" target="_blank" title="Bilibili"><i class="iconfont icon-bilibili1"></i></a></div></div></div><div class="card-widget card-announcement"><div class="card-content"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">活在当下</div></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="card-content"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-Git%E7%AE%80%E4%BB%8B"><span class="toc-text">1. Git简介</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-1-%E9%9B%86%E4%B8%AD%E5%BC%8F%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6%E5%92%8C%E5%88%86%E5%B8%83%E5%BC%8F%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6"><span class="toc-text">1.1 集中式版本控制和分布式版本控制</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-2-%E4%B8%BA%E4%BB%80%E4%B9%88%E8%A6%81%E4%BD%BF%E7%94%A8Git%EF%BC%9F"><span class="toc-text">1.2 为什么要使用Git？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-3-%E5%AE%89%E8%A3%85Git"><span class="toc-text">1.3 安装Git</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E4%BD%BF%E7%94%A8Git%E5%9C%A8%E6%9C%AC%E5%9C%B0%E8%BF%9B%E8%A1%8C%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6"><span class="toc-text">2. 使用Git在本地进行版本控制</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1-%E5%88%9D%E5%A7%8B%E5%8C%96%E7%89%88%E6%9C%AC%E5%BA%93"><span class="toc-text">2.1 初始化版本库</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-2-add%E5%92%8Ccommit"><span class="toc-text">2.2 add和commit</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-3-%E4%BF%AE%E6%94%B9%E6%96%87%E4%BB%B6%E8%BF%9B%E8%A1%8C%E7%89%88%E6%9C%AC%E6%9B%B4%E6%96%B0"><span class="toc-text">2.3 修改文件进行版本更新</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-4-%E7%89%88%E6%9C%AC%E5%9B%9E%E6%BA%AF"><span class="toc-text">2.4 版本回溯</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-5-%E6%92%A4%E9%94%80%E6%93%8D%E4%BD%9C"><span class="toc-text">2.5 撤销操作</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-6-%E5%88%A0%E9%99%A4%E6%93%8D%E4%BD%9C"><span class="toc-text">2.6 删除操作</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-%E6%80%BB%E7%BB%93"><span class="toc-text">3. 总结</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-%E5%8F%82%E8%80%83"><span class="toc-text">4. 参考</span></a></li></ol></div></div></div><div class="card-widget card-recent-post"><div class="card-content"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/post/ceb5/" title="在Deepin上安装Eclipse"><img src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/20210911113215.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="在Deepin上安装Eclipse"/></a><div class="content"><a class="title" href="/post/ceb5/" title="在Deepin上安装Eclipse">在Deepin上安装Eclipse</a><time datetime="2021-09-11T02:46:06.000Z" title="发表于 2021-09-11 10:46:06">2021-09-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/post/6b0/" title="使用VMware创建CentOS7.6虚拟机"><img src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/centos-motif.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="使用VMware创建CentOS7.6虚拟机"/></a><div class="content"><a class="title" href="/post/6b0/" title="使用VMware创建CentOS7.6虚拟机">使用VMware创建CentOS7.6虚拟机</a><time datetime="2021-03-07T14:56:59.000Z" title="发表于 2021-03-07 22:56:59">2021-03-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/post/1ea5/" title="前端练习-九宫格"><img src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/353.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="前端练习-九宫格"/></a><div class="content"><a class="title" href="/post/1ea5/" title="前端练习-九宫格">前端练习-九宫格</a><time datetime="2020-09-14T09:06:40.000Z" title="发表于 2020-09-14 17:06:40">2020-09-14</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/post/7240/" title="LeetCode-组合(每日一题)"><img src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/357.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="LeetCode-组合(每日一题)"/></a><div class="content"><a class="title" href="/post/7240/" title="LeetCode-组合(每日一题)">LeetCode-组合(每日一题)</a><time datetime="2020-09-08T07:13:45.000Z" title="发表于 2020-09-08 15:13:45">2020-09-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/post/aeeb/" title="LeetCode-前K个高频元素(每日一题)"><img src="https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/357.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="LeetCode-前K个高频元素(每日一题)"/></a><div class="content"><a class="title" href="/post/aeeb/" title="LeetCode-前K个高频元素(每日一题)">LeetCode-前K个高频元素(每日一题)</a><time datetime="2020-09-07T08:46:04.000Z" title="发表于 2020-09-07 16:46:04">2020-09-07</time></div></div></div></div></div></div></div></main><footer id="footer" style="background-image: url(https://gitee.com/shenshilei1022/hugo_image_resource/raw/master/imgs/TrakaiLithuania_ZH-CN0447602818_1920x1080.jpg)"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2021 By Shen Shilei</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">回首向来萧瑟处，归去，也无风雨也无晴。</div><div class="icp"><a><img class="icp-icon" src="/img/icp.png" alt="ICP"/><span>陕ICP备2020013027号</span></a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"><div id="local-hits"></div><div id="local-stats"><div class="local-search-stats__hr" id="hr"><span>由</span> <a target="_blank" rel="noopener" href="https://github.com/wzpan/hexo-generator-search" style="color:#49B1F5;">hexo-generator-search</a>
 <span>提供支持</span></div></div></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    let initData = {
      el: '#vcomment',
      appId: 'A2SjWuspv5TQF8rzabRx8Y1d-MdYXbMMI',
      appKey: 'SYbn4zrNF0biLCBhwQ0956wm',
      placeholder: '留下你的足迹...(昵称中填写QQ号可使用QQ头像和QQ邮箱)',
      avatar: 'monsterid',
      meta: 'nick,mail,link'.split(','),
      pageSize: '10',
      lang: 'zh-CN',
      recordIP: false,
      serverURLs: '',
      emojiCDN: 'https://cdn.jsdelivr.net/gh/shenshilei1022/emotion@1.0/',
      emojiMaps: {"1":"aru/1.png","2":"aru/2.png","3":"aru/3.png","4":"aru/4.png","5":"aru/5.png","6":"aru/6.png","7":"aru/7.png","8":"aru/8.png","9":"aru/9.png","10":"aru/10.png","11":"aru/11.png","12":"aru/12.png","13":"aru/13.png","14":"aru/14.png","15":"aru/15.png","16":"aru/16.png","17":"aru/17.png","18":"aru/18.png","19":"aru/19.png","20":"aru/20.png","21":"aru/21.png","22":"aru/22.png","23":"aru/23.png","24":"aru/24.png","25":"aru/25.png","26":"aru/26.png","27":"aru/27.png","28":"aru/28.png","29":"aru/29.png","30":"aru/30.png","31":"aru/31.png","32":"aru/32.png","33":"aru/33.png","34":"aru/34.png","35":"aru/35.png","36":"aru/36.png","37":"aru/37.png","38":"aru/38.png","39":"猥琐萌/1.jpg","40":"猥琐萌/2.jpg","41":"猥琐萌/3.jpg","42":"猥琐萌/4.jpg","43":"猥琐萌/5.jpg","44":"猥琐萌/6.jpg","45":"猥琐萌/7.jpg","46":"猥琐萌/8.jpg","47":"猥琐萌/9.jpg","48":"猥琐萌/10.jpg","49":"猥琐萌/11.jpg","50":"猥琐萌/12.jpg","51":"猥琐萌/13.jpg","52":"猥琐萌/14.jpg","53":"猥琐萌/15.jpg","54":"猥琐萌/16.jpg","55":"猥琐萌/17.jpg","56":"猥琐萌/18.jpg","57":"猥琐萌/19.jpg","58":"猥琐萌/20.jpg","59":"猥琐萌/21.jpg","60":"猥琐萌/22.jpg","61":"猥琐萌/23.jpg","62":"猥琐萌/24.jpg","63":"猥琐萌/25.jpg","64":"猥琐萌/26.jpg","65":"猥琐萌/27.jpg","66":"猥琐萌/28.jpg","67":"猥琐萌/29.jpg","68":"猥琐萌/30.jpg","69":"猥琐萌/31.jpg","70":"猥琐萌/32.jpg","71":"猥琐萌/33.jpg","72":"猥琐萌/34.jpg","73":"猥琐萌/35.jpg","74":"猥琐萌/36.jpg","75":"猥琐萌/37.jpg","76":"猥琐萌/38.jpg","77":"猥琐萌/39.jpg","78":"猥琐萌/40.jpg","79":"猥琐萌/41.jpg","80":"猥琐萌/42.jpg","81":"猥琐萌/43.jpg","82":"猥琐萌/44.jpg","83":"猥琐萌/45.jpg","84":"猥琐萌/46.jpg","85":"猥琐萌/47.jpg","86":"猥琐萌/48.jpg","87":"猥琐萌/49.jpg","88":"猥琐萌/50.jpg","89":"猥琐萌/51.jpg","90":"猥琐萌/52.jpg","91":"猥琐萌/53.jpg","92":"猥琐萌/54.jpg","93":"猥琐萌/55.jpg","94":"猥琐萌/56.jpg","95":"猥琐萌/57.jpg","96":"猥琐萌/58.jpg","97":"猥琐萌/59.jpg","98":"猥琐萌/60.jpg","djxbz":"copy/djxbz.jpg","gan":"copy/gan.jpg","hp":"copy/hp.jpg","huaiyi":"copy/huaiyi.jpg","imgcao":"copy/imgcao.jpg","imghua":"copy/imghua.jpg","imgri":"copy/imgri.jpg","mudenggoudai":"copy/mudenggoudai.jpg","pc":"copy/pc.jpg","tlspg":"copy/tlspg.jpg","tql":"copy/tql.jpg","wuyu":"copy/wuyu.jpg","zzxbz":"copy/zzxbz.jpg","icon_huaji":"copy/icon_huaji.png","仙女下凡":"copy/仙女下凡.webp","听歌":"copy/听歌.webp","嫌弃":"copy/嫌弃.webp","害羞":"bilibili/tv_害羞.png","彩虹滑稽":"copy/彩虹滑稽.webp","快走":"copy/快走.webp","扯脸":"copy/扯脸.webp","摸脸":"copy/摸脸.webp","流汗":"bilibili/tv_流汗.png","滑滑板":"copy/滑滑板.webp","点赞":"bilibili/tv_点赞.png","转圈圈":"copy/转圈圈.webp","光头小人1":"copy/光头小人_(1).gif","光头小人19":"copy/光头小人_(19).gif","光头小人20":"copy/光头小人_(20).gif","光头小人21":"copy/光头小人_(21).gif","光头小人22":"copy/光头小人_(22).gif","光头小人23":"copy/光头小人_(23).gif","光头小人24":"copy/光头小人_(24).gif","光头小人25":"copy/光头小人_(25).gif","光头小人26":"copy/光头小人_(26).gif","光头小人27":"copy/光头小人_(27).gif","光头小人28":"copy/光头小人_(28).gif","光头小人29":"copy/光头小人_(29).gif","光头小人30":"copy/光头小人_(30).gif","光头小人31":"copy/光头小人_(31).gif","光头小人32":"copy/光头小人_(32).gif","光头小人33":"copy/光头小人_(33).gif","光头小人34":"copy/光头小人_(34).gif","光头小人35":"copy/光头小人_(35).gif","光头小人36":"copy/光头小人_(36).gif","光头小人37":"copy/光头小人_(37).gif","光波":"copy/光波.gif","厕所1":"copy/厕所_(1).gif","厕所2":"copy/厕所_(2).gif","厕所3":"copy/厕所_(3).gif","咸鱼":"copy/咸鱼.gif","奏乐1":"copy/奏乐_(1).gif","奏乐10":"copy/奏乐_(10).gif","奏乐2":"copy/奏乐_(2).gif","奏乐4":"copy/奏乐_(4).gif","奏乐5":"copy/奏乐_(5).gif","奏乐6":"copy/奏乐_(6).gif","奏乐7":"copy/奏乐_(7).gif","奏乐8":"copy/奏乐_(8).gif","奏乐9":"copy/奏乐_(9).gif","奔跑狗5":"copy/奔跑狗 (5).gif","奔跑狗1":"copy/奔跑狗_(1).gif","奔跑狗2":"copy/奔跑狗_(2).gif","奔跑狗3":"copy/奔跑狗_(3).gif","奔跑狗4":"copy/奔跑狗_(4).gif","害怕滑稽":"copy/害怕滑稽.gif","小人儿10":"copy/小人儿_(10).gif","小兔吃东西12":"copy/小兔吃东西_(12).gif","小兔吃东西13":"copy/小兔吃东西_(13).gif","小兔吃东西14":"copy/小兔吃东西_(14).gif","小兔吃东西18":"copy/小兔吃东西_(18).gif","小兔吃东西19":"copy/小兔吃东西_(19).gif","小兔吃东西20":"copy/小兔吃东西_(20).gif","小兔吃东西21":"copy/小兔吃东西_(21).gif","小兔吃东西22":"copy/小兔吃东西_(22).gif","小疯子2":"copy/小疯子_(2).gif","小疯子3":"copy/小疯子_(3).gif","小疯子4":"copy/小疯子_(4).gif","小疯子5":"copy/小疯子_(5).gif","小疯子6":"copy/小疯子_(6).gif","小疯子7":"copy/小疯子_(7).gif","小疯子8":"copy/小疯子_(8).gif","扇子狗":"copy/扇子狗.gif","抓1":"copy/抓_(1).gif","抓2":"copy/抓_(2).gif","掐脖子":"copy/掐脖子.gif","滑稽1":"copy/滑稽_(1).gif","滑稽2":"copy/滑稽_(2).gif","滑稽3":"copy/滑稽_(3).gif","滑稽4":"copy/滑稽_(4).gif","跪坐1":"copy/跪坐_(1).gif","跪坐2":"copy/跪坐_(2).gif","鹦鹉小恐龙1":"copy/鹦鹉小恐龙_(1).gif","鹦鹉小恐龙2":"copy/鹦鹉小恐龙_(2).gif","doge":"bilibili/tv_doge.png","亲亲":"bilibili/tv_亲亲.png","偷笑":"bilibili/tv_偷笑.png","再见":"bilibili/tv_再见.png","冷漠":"bilibili/tv_冷漠.png","发怒":"bilibili/tv_发怒.png","发财":"bilibili/tv_发财.png","可爱":"bilibili/tv_可爱.png","吐血":"bilibili/tv_吐血.png","呆":"bilibili/tv_呆.png","呕吐":"bilibili/tv_呕吐.png","困":"bilibili/tv_困.png","坏笑":"bilibili/tv_坏笑.png","大佬":"bilibili/tv_大佬.png","大哭":"bilibili/tv_大哭.png","委屈":"bilibili/tv_委屈.png","尴尬":"bilibili/tv_尴尬.png","微笑":"bilibili/tv_微笑.png","思考":"bilibili/tv_思考.png","惊吓":"bilibili/tv_惊吓.png","打脸":"bilibili/tv_打脸.png","抓狂":"bilibili/tv_抓狂.png","抠鼻":"bilibili/tv_抠鼻.png","斜眼笑":"bilibili/tv_斜眼笑.png","无奈":"bilibili/tv_无奈.png","晕":"bilibili/tv_晕.png","流泪":"bilibili/tv_流泪.png","流鼻血":"bilibili/tv_流鼻血.png","生气":"bilibili/tv_生气.png","生病":"bilibili/tv_生病.png","疑问":"bilibili/tv_疑问.png","白眼":"bilibili/tv_白眼.png","皱眉":"bilibili/tv_皱眉.png","目瞪口呆":"bilibili/tv_目瞪口呆.png","睡着":"bilibili/tv_睡着.png","笑哭":"bilibili/tv_笑哭.png","腼腆":"bilibili/tv_腼腆.png","色":"bilibili/tv_色.png","调侃":"bilibili/tv_调侃.png","调皮":"bilibili/tv_调皮.png","鄙视":"bilibili/tv_鄙视.png","闭嘴":"bilibili/tv_闭嘴.png","难过":"bilibili/tv_难过.png","馋":"bilibili/tv_馋.png","鬼脸":"bilibili/tv_鬼脸.png","黑人问号":"bilibili/tv_黑人问号.png","鼓掌":"bilibili/tv_鼓掌.png"},
      enableQQ: true,
      path: window.location.pathname,
    }

    if (true) { 
      initData.requiredFields= ('nick,mail'.split(','))
    }
    
    if (false) {
      const otherData = false
      initData = Object.assign({}, initData, otherData)
    }
    
    const valine = new Valine(initData)
  }

  if (typeof Valine === 'function') initValine() 
  else $.getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js', initValine)
}

if ('Valine' === 'Valine' || !false) {
  if (false) btf.loadComment(document.querySelector('#vcomment'),loadValine)
  else setTimeout(() => loadValine(), 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><div class="aplayer no-destroy" data-id="4960099490" data-server="netease" data-type="playlist" data-fixed="true" data-mini="true" data-listFolded="false" data-order="random" data-preload="none" data-autoplay="false" muted></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = [
  'title',
  '#config_change',
  '#body-wrap',
  '#rightside-config-hide',
  '#rightside-config-show',
  '.js-pjax'
]

if (false) {
  pjaxSelectors.unshift('meta[property="og:image"]', 'meta[property="og:title"]', 'meta[property="og:url"]')
}

var pjax = new Pjax({
  elements: 'a:not([target="_blank"]):not([href="/post/a7b7/"]):not([href="/artitalk/"]):not([href="/post/6a69/"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  $('script[data-pjax]').each(function () {
    $(this).parent().append($(this).remove())
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  if (typeof gtag === 'function') {
    gtag('config', '', {'page_path': window.location.pathname});
  }

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // Analytics
  if (false) {
    MtaH5.pgv()
  }

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()

  typeof preloader === 'object' && preloader.endLoading()
})


document.addEventListener('pjax:send', function () {
  typeof preloader === 'object' && preloader.initLoading()
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  $(window).off('scroll')

  //reset readmode
  $('body').hasClass('read-mode') && $('body').removeClass('read-mode')

})</script></div></body></html>